﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SRD.Model.SRD.BO;
using SRD.Model.SRD.DTO;
using System.Data;

namespace SRD.View.Views
{
    public partial class listStatusSubmissao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CarregarGridStatusSubmissao();
                if (Session["mensagem"] != null)
                {
                    MessageBox.Show(Session["mensagem"].ToString(), MessageBox.MessageType.Success);
                    Session["mensagem"] = null;
                }
            }
        }

        protected void PesquisaStatus(object sender, ImageClickEventArgs e)
        {
            StatusSubmissaoBO statusSubmissao = new StatusSubmissaoBO();
            String nomeStatusSubmissao = txtPesquisa.Text;
            IQueryable dtsStatusSubmissao = statusSubmissao.findByName(nomeStatusSubmissao);
            if (dtsStatusSubmissao != null)
            {
                CarregarGridStatusSubmissao(dtsStatusSubmissao);
            }
            else
            {
                MessageBox.Show("Não foi encontrado nenhum registro com essa informação!", MessageBox.MessageType.Success);
            }
            txtPesquisa.Text = "";
        }

        public void CarregarGridStatusSubmissao()
        {
            StatusSubmissaoBO statusSubmissao = new StatusSubmissaoBO();
            GridStatusSubmissao.DataSource = statusSubmissao.findAll();
            GridStatusSubmissao.DataBind();
        }

        public void CarregarGridStatusSubmissao(IQueryable dtsStatusSubmissao)
        {
            GridStatusSubmissao.DataSource = dtsStatusSubmissao;
            GridStatusSubmissao.DataBind();
        }

        protected void BtnNovo_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("editStatusSubmissao.aspx");
        }

        protected void btnVoltar_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

        protected void GridStatusSubmissao_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            STATUS_SUBMISSAO objStatusSubmissao = new STATUS_SUBMISSAO();
            StatusSubmissaoBO statusSubmissao = new StatusSubmissaoBO();
            String resposta;

            objStatusSubmissao.STATUS_SUBMISSAO_ID = Convert.ToInt32(GridStatusSubmissao.DataKeys[e.RowIndex].Value);

            resposta = statusSubmissao.delete(objStatusSubmissao);

            CarregarGridStatusSubmissao();

            MessageBox.Show(resposta, MessageBox.MessageType.Success);
        }

        protected void GridStatusSubmissao_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridStatusSubmissao.PageIndex = e.NewPageIndex;
            CarregarGridStatusSubmissao();
        }

        
    }
}